#include "../myOS/userInterface.h" //interface from kernel

#include "shell.h"
#include "memTestCase.h"
#include "../myOS/include/mem.h"
#include "../myOS/include/task.h"

void wallClock_hook_main(void)
{
	int _h, _m, _s;
	char hhmmss[] = "hh:mm:ss\0\0\0\0";

	getWallClock(&_h, &_m, &_s);
	sprintf(hhmmss, "%02d:%02d:%02d", _h, _m, _s);
	put_chars(hhmmss, 0x30, 24, 72);
}

void doSomeTestBefore(void)
{
	setWallClock(10, 40, 00); // set time 18:59:59
	setWallClockHook(&wallClock_hook_main);
}

extern void SetExeTime(int tsk0, int tsk1, int tsk2);
extern void testcase0(void);
extern void testcase1(void);
extern void testcase2(void);
extern void shell(void);

extern int pre_flag;

void myMain(void)
{

#if DEBUG_QUEUE_FALGS
	myPrintf(0x08, "\nPress any key to continue debug:\n");
	uart_get_char();
#endif

	doSomeTestBefore();

	initShell();

	int shellTid = 0;
	int testtid0 = 0;
	int testtid1 = 0;
	int testtid2 = 0;

	switch (sch_type)
	{
	case FCFS:
		shellTid = createTsk(shell, 15, 0x7FFFFFFF, 0);
		testtid0 = createTsk(testcase0, 2, 3, 0);
		testtid1 = createTsk(testcase1, 4, 2, 0);
		testtid2 = createTsk(testcase2, 8, 4, 0);
		SetExeTime(3, 2, 4);
		break;
	case PRIO:
	switch(pre_flag){
		case 1:
			shellTid = createTsk(shell, 12, 0x7FFFFFFF, 0);
			testtid0 = createTsk(testcase0, 1, 2, 4);
			testtid1 = createTsk(testcase1, 3, 4, 2);
			testtid2 = createTsk(testcase2, 4, 2, 0);
			SetExeTime(2, 4, 2);
			break;
		case 0:
			shellTid = createTsk(shell, 12, 0x7FFFFFFF, 0);
			testtid0 = createTsk(testcase0, 1, 2, 4);
			testtid1 = createTsk(testcase1, 1, 4, 2);
			testtid2 = createTsk(testcase2, 2, 2, 0);
			SetExeTime(2, 4, 2);
			break;
	}
		break;
	case SJF:
		shellTid = -1;
		testtid0 = createTsk(testcase0, 2, 2, 0);
		testtid1 = createTsk(testcase1, 2, 3, 2);
		testtid2 = createTsk(testcase2, 4, 1, 1);
		SetExeTime(2, 3, 1);
	case RR:
		shellTid = -1;
		testtid0 = createTsk(testcase0, 2, 0, 0);
		testtid1 = createTsk(testcase1, 2, 3, 2);
		testtid2 = createTsk(testcase2, 4, 1, 1);
		SetExeTime(2, 3, 1);
		break;
	}

	tskStart(testtid0);
	tskStart(testtid1);
	tskStart(testtid2);
	if(shellTid!=-1)tskStart(shellTid);

	//Q_print(Future_Queue_Handler);

#if DEBUG_QUEUE_FALGS
	myPrintf(0x08, "\nPress any key to continue debug:\n");
	uart_get_char();
#endif

	return;
}

void ShellMain()
{
	doSomeTestBefore();

	initShell();

	startShell();
	return;
}
